package com.chixing.day10_hashcode_exception;

import com.chixing.day10_hashcode_exception.exception.BalanceNotEnoughException;

import java.sql.SQLException;

public class HandleExceptionDemo {
    public static void main(String[] args) throws SQLException, BalanceNotEnoughException {
        //调用方
        HandleExceptionDemo.fun1();
        fun2();
        fun4();
    }

    public static void fun4(){
        Account account = new Account();
        account.setAccBalance(200);

        try {//捕捉异常代码
            //可能出现异常的代码  BalanceNotEnoughException
            System.out.println("try1");
            int a = 10/0;
            System.out.println("try2");
            account.withdraw(100);//有可能BalanceNotEnoughException
            System.out.println("try3");
        }catch (BalanceNotEnoughException e){
            //处理异常的代码
            System.out.println("模拟账户余额不足的异常处理代码");
        }catch (ArithmeticException e){
            //处理异常的代码
            System.out.println("模拟除数不能为0处理的逻辑，异常处理代码");
        }

        System.out.println("xxxxxxxxxxxxxx");

        try {
            Account.class.getField("").get(null);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    public static void fun1()throws SQLException{

    }
    public static void fun2() throws BalanceNotEnoughException {
        fun3();
    }
    public static void fun3()throws BalanceNotEnoughException {

    }
}
